#define _CRT_SECURE_NO_WARNINGS 1


//二叉树的最小深度
int minDepth(struct TreeNode *root) {
    if (root == NULL) {
        return 0;
    }

    if (root->left == NULL && root->right == NULL) {
        return 1;
    }

    int min_depth = INT_MAX;
    if (root->left != NULL) {
        min_depth = fmin(minDepth(root->left), min_depth);
    }
    if (root->right != NULL) {
        min_depth = fmin(minDepth(root->right), min_depth);
    }

    return min_depth + 1;
}


char match(char c)
{
    if (c == ']')
        return '[';
    if (c == '}')
        return '{';
    if (c == ')')
        return '(';
    return 0;
}
bool isValid(char* s) {
    char stack[10001];
    int top = 0;
    for (int i = 0; i < strlen(s); i++)
    {
        char c = s[i];
        char ret = match(c);
        if (c == '[' || c == '{' || c == '(')
        {
            stack[top++] = s[i];
        }
        else
        {
            char ret = match(c);
            if (top == 0 || stack[top - 1] != ret)
                return false;
            else
            {
                top--;
            }
        }
    }

    return top == 0;
}